import Mock from 'mockjs'
let List = [
  { username: 'admin', password: 'admin' },
  { username: '111', password: '111' }
]
let uname = ''
let pwd = ''

export default {
  getMenu: config => {
    const { username, password } = JSON.parse(config.body)
    uname = username
    pwd = password
    // 先判断用户是否存在
    // 判断账号和密码是否对应
    if (username === 'admin' && password === 'admin') {
      return {
        code: 20000,
        data: {
          menu: [
            {
              path: '/home',
              name: 'home',
              label: '首页',
              icon: 's-home',
              url: 'home/index'
            },
            {
              path: '/mall',
              name: 'mall',
              label: '商品管理',
              icon: 'notebook-2',
              url: 'mall/index',
              children: [
                {
                  path: '/mallStatus',
                  name: 'mallStatus',
                  label: '商品状态',
                  icon: 'setting',
                  url: 'mallStatus.vue'
                },
                {
                  path: '/mallInfo',
                  name: 'mallInfo',
                  label: '商品信息',
                  icon: 'setting',
                  url: 'mallInfo.vue'
                }
              ]
            },
            {
              path: '/user',
              name: 'user',
              label: '用户管理',
              icon: 'video-play',
              url: 'User/index'
            },
            {
              label: '个人中心',
              icon: 'user-solid',
              children: [
                {
                  path: '/baseInfo',
                  name: 'baseInfo',
                  label: '基础信息',
                  icon: 'setting',
                  url: 'person/baseInfo.vue'
                },
                {
                  path: '/refreshPwd',
                  name: 'refreshPwd',
                  label: '更改密码',
                  icon: 'setting',
                  url: 'person/refreshPwd.vue'
                }
              ]
            }
          ],
          token: Mock.Random.guid(),
          message: '获取成功'
        }
      }
    } else if (username === '111' && password === '111') {
      return {
        code: 20000,
        data: {
          menu: [
            {
              path: '/',
              name: 'home',
              label: '首页',
              icon: 's-home',
              url: 'home/index'
            },
            {
              path: '/video',
              name: 'video',
              label: '商品管理',
              icon: 'video-play',
              url: 'mall/index'
            }
          ],
          token: Mock.Random.guid(),
          message: '获取成功'
        }
      }
    } else {
      return {
        code: -999,
        data: {
          message: '密码错误'
        }
      }
    }
  },
  updatePwd: config => {
    const { old_pwd, new_pwd } = JSON.parse(config.body)
    List.some(item => {
      if (item.username === username) {
        item.password = new_pwd
        return true
      }
    })
    return {
      code: 20000,
      data: {
        message: '编辑成功'
      }
    }
  }
}
